﻿@page "/Releases/ReleaseView"
@inherits _BaseView

<style>

    .release-sticky-info {
        position: sticky;
        top: 128px;
    }

    .release-body {
        white-space: pre-line;
        font-size: var(--mud-typography-body1-size);
        font-family: var(--mud-typography-body1-family);
        font-weight: var(--mud-typography-body1-weight);
        line-height: var(--mud-typography-body1-lineheight);
        letter-spacing: var(--mud-typography-body1-letterspacing);
        text-transform: var(--mud-typography-body1-text-transform);
    }

        .release-body a {
            color: var(--mud-palette-primary);
            line-height: normal;
            font-weight: 500;
        }

            .release-body a:hover {
                cursor: pointer;
                text-decoration: underline;
            }

        .release-body h5 {
            margin-bottom: -12px;
        }

</style>

<MaanfeeDashboardPage>
    <MaanfeeDashboardPageHeader PageTitle="@DashboardResource.StringRelease" Title="@DashboardResource.StringRelease" />

    @if (!IsLoaded)
    {
        <PublicOverlay />
    }
    else
    {
        <MudGrid>
            @foreach (var Releases in SysReleases)
            {
                <MudItem md="3">
                    <div class="release-sticky-info">
                        <MudText Typo="Typo.h5" Inline="true">@DashboardResource.StringVersion</MudText>
                        <MudText Typo="Typo.h5" Inline="true" Color="Color.Primary"><b>@Releases.Version</b></MudText>
                        <MudStack Row="true" Spacing="1">
                            <MudIcon Color="Color.Secondary" Icon="@Icons.Material.Filled.CalendarMonth" Size="Size.Small" />
                            <MudText Color="Color.Secondary" Typo="Typo.subtitle2">
                                @DashboardResource.StringReleasedOn <strong>@Releases.ReleaseDate.ToDateString()</strong>
                            </MudText>
                        </MudStack>
                    </div>
                </MudItem>
                <MudItem md="9">
                    <div class="release-body">
                        <MudStack Row="true" Spacing="1">
                            <MudIcon Icon="@Icons.Material.Filled.NewReleases" Class="mt-1" />
                            <MudText Typo="Typo.h5">
                                @DashboardResource.StringWhatsChanged
                            </MudText>
                        </MudStack>
                        <MudDivider DividerType="DividerType.FullWidth" />
                        @foreach (var itemGroup in Releases.SysReleaseFeatures.OrderByDescending(x => x.FeatureDate))
                        {
                            <MudStack Row="true" Spacing="2">
                                @if (itemGroup.SysReleaseType.Id == 1)
                                {
                                    <MudChip T="string" Icon="@Icons.Material.Filled.Polymer" Size="Size.Small" Label="true" Color="Color.Success">
                                        @itemGroup.SysReleaseType.Title
                                    </MudChip>
                                }
                                else
                                {
                                    <MudChip T="string" Icon="@Icons.Material.Filled.BugReport" Size="Size.Small" Label="true" Color="Color.Error">
                                        @itemGroup.SysReleaseType.Title
                                    </MudChip>
                                }
                                @if (itemGroup.FeatureDate.HasValue)
                                {
                                    <MudChip T="string" Size="Size.Small" Label="true" Color="Color.Warning">
                                        @itemGroup.FeatureDate.ToDateString()
                                    </MudChip>
                                }
                                else
                                {
                                    <MudChip T="string" Size="Size.Small" Label="true" Color="Color.Warning">
                                        نامشخص
                                    </MudChip>
                                }
                                <MudText Typo="Typo.caption" Color="Color.Primary" Class="mt-2">
                                    @itemGroup.Comment
                                </MudText>
                                @*   <MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-2">
                    @itemGroup.FeatureDate.ToDateString()
                    </MudText> *@
                            </MudStack>
                        }
                    </div>
                </MudItem>
            }
        </MudGrid>
    }

    <MudScrollToTop TopOffset="100" Style="z-index:2000;">
        <MudFab StartIcon="@Icons.Material.Filled.KeyboardArrowUp" Color="Color.Primary" />
    </MudScrollToTop>

</MaanfeeDashboardPage>

@code {

    private List<SysRelease> SysReleases = new();

    protected override async Task OnInitializedAsync()
    {
        IsLoaded = false;

        var Callback = await Http.GetFromJsonAsync<CallbackResult<List<SysRelease>>>($"api/SysReleases/GetAllReleases");

        if (Callback.Data != null)
        {
            SysReleases = Callback.Data;
        }
        else
        {
            Snackbar.Add(Callback.Error.ToString(), Severity.Error);
            IsLoaded = true;
        }
        StateHasChanged();

        IsLoaded = true;

        if (LoggingHubConnection is not null)
        {
            await LoggingHubConnection.SendAsync("SendMessageAsync", new LogInfo
                {
                    IdLoggingPlatform = LoggingPlatformDefaultValue.Client,
                    Message = $"{AccountStateContainer.UserName} ({AccountStateContainer.Name}) is Viewing ({DashboardResource.StringRelease})",
                    LogDate = DateTime.Now,
                    IdLoggingLevel = LoggingLevelDefaultValue.Information,
                });
        }

    }

}
